<!--选择分类-->
<div class="pad_10">
    <form name="select_form" id="select_form" method="post" onsubmit="return dosubmit();">
    <div class="J_tablelist table_list" style="height:300px; overflow-y:auto; margin-bottom:5px;">
    <table width="100%" cellspacing="0" id="J_auth_tree">
    	<thead>
        	<tr><th align="left">
			<label class="select_all"><input type="checkbox" name="checkall" class="J_checkall">{:L('select_all')}/{:L('cancel')}</label></th></tr>
        </thead>
    	<tbody>
			{foreach e list}
				{asp checked = AB.C.IIF(AB.A.InArray(list(e)("id"), check_ids), " checked", "") }
				<tr id='node-{:list(e)("id")}' {if list(e)("pid")<>topid}class="child-of-node-{:list(e)("pid")}"{else}{/if}>
					<td style='padding-left:10px;'>{:list(e)("tree_spacer")}
					<input type='checkbox' name='classid' value='{:list(e)("id")}' class='J_checkitem' 
					level='{:M("menu").get_level(list(e)("id"),list,topid,0)}' {$checked}> {:list(e)("name")} 
					<font color="#bbbbbb">(ID: {:list(e)("id")})</font></td>
				</tr>
			{/foreach}
    	</tbody>
    </table>
    <input type="hidden" name="id" value=""></input>
    </div>
    </form>
</div>

<script>
function dosubmit() {
	return true;
}
$(function() {
    $("#J_auth_tree").treeTable({indent:20});

    $('.J_checkall').live('click', function(){
        $('.J_checkitem').attr('checked', this.checked);
        $('.J_checkall').attr('checked', this.checked);
    });

    $('.J_checkitem').live('click', function(){
        var chk = $("input[type='checkbox']"),
            count = chk.length,
            num = chk.index($(this)),
            level_top = level_bottom =  chk.eq(num).attr('level');
        for(var i=num; i>=0; i--){
            var le = chk.eq(i).attr('level');
            if(eval(le) < eval(level_top)){
                chk.eq(i).attr("checked", true);
                var level_top = level_top-1;
            }
        }
        for(var j=num+1; j<count; j++){
            var le = chk.eq(j).attr('level');
            if(chk.eq(num).attr("checked")) {
                if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked", true);
                else if(eval(le) == eval(level_bottom)) break;
            }else{
                if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked", false);
                else if(eval(le) == eval(level_bottom)) break;
            }
        }
    });

});
</script>